package com.example.administrator.xiaoxiang.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by Administrator on 2017/1/4.
 */

public class BaseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    private SparseArray<View> views;
    private BaseAdapter.OnItemClickListener mOnItemClickListener = null;
    public BaseViewHolder(View itemView,BaseAdapter.OnItemClickListener mOnItemClickListener) {
        super(itemView);
        views=new SparseArray<>();
        this.mOnItemClickListener=mOnItemClickListener;
        itemView.setOnClickListener(this);
    }

    public TextView getTextView(int viewId) {
        return (TextView) findView(viewId);
    }



    public ImageView getImageView(int viewId) {
        return (ImageView) findView(viewId);
    }
    private View findView(int id){
        View view=views.get(id);
        if (view==null){
            view=itemView.findViewById(id);
            views.put(id,view);
        }
        return view;
    }

    @Override
    public void onClick(View v) {
        if (mOnItemClickListener != null) {
            mOnItemClickListener.OnClick(v,getLayoutPosition());
        }
    }
}
